package org.dkakunsi.aplikasitoko.service;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperPrint;

import org.dkakunsi.aplikasitoko.data.entity.Kasir;
import org.dkakunsi.aplikasitoko.data.entity.Transaksi;
import org.dkakunsi.aplikasitoko.data.util.HibernateUtil;
import org.dkakunsi.aplikasitoko.report.data.access.ReportAccess;
import org.dkakunsi.aplikasitoko.report.data.adapter.ReportDataAdapter;
import org.hibernate.Session;

public class ReportService {

	private static ReportAccess report;
	private static Session session;
	
	public static JasperPrint getReport(Object object) {
		session = HibernateUtil.openSession();
		report = new ReportDataAdapter(session);

		try {
			if(object instanceof Transaksi) {
				return report.getSalesReport(object);
			} else if(object instanceof Kasir) {
				return report.getKasirTransaksiReport(object);
			} else {
				return null;
			}
		} catch(JRException exc) {
			exc.printStackTrace();
			return null;
		} finally {
			HibernateUtil.close(session);
			report = null;
		}
	}

}
